package com.wangxinenpu.springbootdemo.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wangxinenpu.springbootdemo.dataobject.dto.organization.OrganizationDto;
import com.wangxinenpu.springbootdemo.dataobject.model.Organization;
import com.wangxinenpu.springbootdemo.service.OrganizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping ( "/organization" )
@AllArgsConstructor
@Api ( value = "组织管理", tags = "组织管理" )
@Slf4j
public class OrganizationController {

	private final OrganizationService organizationService;

	@PostMapping ( "/pageList" )
	@ApiOperation ( value = "组织管理列表", notes = "组织管理列表" )
	public R < Page < Organization > > pageList ( @RequestBody OrganizationDto dto ) {
		return organizationService.pageList ( dto );
	}

	@PostMapping ( "/delete" )
	@ApiOperation ( value = "删除/批量删除", notes = "删除/批量删除" )
	public R < Boolean > delete ( @RequestBody List < String > ids ) {
		return organizationService.delete ( ids );
	}

	@PostMapping ( "/savaOrUpdate" )
	@ApiOperation ( value = "新增/编辑", notes = "新增/编辑" )
	public R < Organization > savaOrUpdate ( @RequestBody @Validated OrganizationDto dto ) {
		return organizationService.savaOrUpdate ( dto );
	}
	@GetMapping("detail")
	@ApiOperation ( value = "详情", notes = "详情" )
	public R <  Organization  > detail (@RequestParam String id) {
		return organizationService.detail (id);
	}

	@GetMapping ( "/getList" )
	@ApiOperation ( value = "组织下拉框", notes = "组织下拉框" )
	public R < List < Organization > > getList () {
		return organizationService.getList ();
	}
}
